﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AviFile;
using Infragistics.Win.UltraWinEditors;

namespace Test4AviFile
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private String GetFileName(String filter)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = filter;
            dlg.RestoreDirectory = true;
            if (textBox1.Text.Length > 0)
            {
                dlg.InitialDirectory = GetCurrentFilePath();
            }
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                return dlg.FileName;
            }
            else
            {
                return null;
            }
        }

        private String GetCurrentFilePath()
        {
            return textBox1.Text.Substring(0, textBox1.Text.LastIndexOf("\\") + 1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String fileName = GetFileName("Videos (*.avi)|*.avi;*.mpe;*.mpeg");
            if (fileName != null)
            {
                textBox1.Text = fileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            AviManager aviManager = new AviManager(textBox1.Text, true);
            VideoStream stream = aviManager.GetVideoStream();
            textBox2.Text = "Width: " + stream.Width;
            textBox2.Text += "\r\nHeight: " + stream.Height;
            textBox2.Text += "\r\nCount of Frames: " + stream.CountFrames;
            textBox2.Text += "\r\nFrame Rate: " + stream.FrameRate;
            aviManager.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //AviManager aviManager = new AviManager(textBox1.Text, true);
            //VideoStream stream = aviManager.GetVideoStream();
            //stream.GetFrameOpen();

            //stream.ExportBitmap(0, "1.bmp");

            //stream.GetFrameClose();
            //aviManager.Close();

            //
            List<UltraPictureBox> list = new List<UltraPictureBox>();
            for (int i = 0; i < 10; i++)
            {
                UltraPictureBox pb = new UltraPictureBox();
                pb.Image = Image.FromFile("lovehate.jpg");
                pb.Location = new System.Drawing.Point(i*55, 272);
                pb.Name = "pictureBox"+i.ToString();
                pb.Size = new System.Drawing.Size(50, 50);
                pb.TabStop = false;
                list.Add(pb);
            }
            foreach (UltraPictureBox p in list)
                this.Controls.Add(p);
        }

        private void ultraPictureBox1_Click(object sender, EventArgs e)
        {
            ((UltraPictureBox)sender).DrawBorderShadow = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

    }
}
